export default {
  namespaced: true,
  state: () => ({
    planExamParams: {},
    // 答题进度及是否通过 
    planExamProgress: {},
    isRetest: false,
    isSubmited: false,
    planExam: {},
    // 答题卡及左侧列表数据
    parts: [],
    // 当前问题
    currentQuestion: {},
    // 测验结果
    planExamResult: {},
    //问题列表
    questionsList: [],
    //隐藏再测一次按钮
    isHideRetestButton: false,
    // 是否刷新首页
    freshIndexPage: false
  }),
  mutations: {
    SET_PLAN_EXAM_PROGRESS(state, data) {
      state.planExamProgress = data
    },
    SET_PLAN_EXAM_PARAMS(state, data) {
      state.planExamParams = data
    },
    SET_PARTS(state, data) {
      state.parts = data
    },
    SET_PLAN_EXAM(state, data) {
      state.planExam = data
    },
    SET_CURRENT_QUESTION(state,data) {
      state.currentQuestion = data
    },
    UPDATE_ANSWER(state, options) {
      let { newData, index, cindex, question_index, indexId} = options
      let part = state.parts[index]
      let oldData = part.questions[cindex]
      part.questions[cindex].status = 'd'
      part.answerList[cindex].status = newData.status
      state.parts[index] = part
      
      state.questionsList[question_index].status = newData.status
      state.questionsList[question_index].userAnswer = newData.userAnswer
      // let {id, subject_id, day} = state.planExamParams
      // let resultMap = JSON.parse(storage.get('plan_answer_result_' + id)) || {}
      // if(!resultMap[day+'_'+subject_id]) {
      //   resultMap[day+'_'+subject_id] = {}
      // }
      // resultMap[day+'_'+subject_id][indexId] = newData
      // storage.set('plan_answer_result_' + id, resultMap)
    },
    SET_PLAN_EXAM_RESULT(state, val) {
      state.planExamResult = val
    },
    SET_QUESTIONS_LIST(state, val) {
      state.questionsList = val
    },
    // 保存每次答案
    SET_ANSER_RESULT(state, val) {

    },
    SET_IS_RETEST(state, val) {
      state.isRetest = val
    },
    SET_IS_SUBMITED(state,val) {
      state.isSubmited = val
    },
    SET_HIDE_RETEST_BUTTON(state,val) {
      state.isHideRetestButton = val
    },
    SET_FRESH_INDEX_PAGE(state, val) {
      state.freshIndexPage = val
    }
  },
  actions: {
    setPlanExamParams({ commit }, val) {
      commit('SET_PLAN_EXAM_PARAMS', val)
    },
    setPlanExamProgress({ commit }, val) {
      commit('SET_PLAN_EXAM_PROGRESS', val)
    },
    setPlanExam({ commit }, val) {
      commit('SET_PLAN_EXAM', val)
    },
    setParts({ commit }, val) {
      commit('SET_PARTS', val)
    },
    updateAnswer({ commit }, options) {
      commit('UPDATE_ANSWER', options)
    },
    setCurrentQuestion({ commit }, val) {
      commit('SET_CURRENT_QUESTION', val)
    },
    setPlanExamResult({ commit }, val) {
      commit('SET_PLAN_EXAM_RESULT', val)
    },
    setQuestionsList({ commit }, val) {
      commit('SET_QUESTIONS_LIST', val)
    },
    setIsRetest({commit}, val) {
      commit('SET_IS_RETEST', val)
    },
    setIsSubmited({commit}, val) {
      commit('SET_IS_SUBMITED', val)
    },
    setHideRetestButton({commit}, val) {
      commit('SET_HIDE_RETEST_BUTTON', val)
    },
    setFreshIndexPage({commit}, val) {
      commit('SET_FRESH_INDEX_PAGE', val)
    }
  },
  getters: {

  }
}